<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <ul>
            <li v-for="(item, index) in items" :key="index">
                <span>{{ item }}</span>
                <button @click="removeItem(index)">删除</button>
            </li>
        </ul>
        <button @click="generateItem">生成</button>
    </div>
    <script src="./vue.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                items: [1, 3, 5]
            },
            methods: {
                generateItem() {
                    // 生成一个20以内的随机数字并添加到数组中
                    const newItem = Math.floor(Math.random() * 20) + 1;
                    this.items.push(newItem);
                },
                removeItem(index) {
                    // 删除指定索引的元素
                    this.items.splice(index, 1);
                }
            }
        })
    </script>
</body>

</html>